<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
</head>
<body>

</body>
<script>
	// 实现以下转换，合并连续的数字[1,2,3,4,6,7,9,13,15]=>['1->4','6->7','9','13','15']
	function mergeArray(arr){
		let temp = []
		for(let i = 0;i < arr.length;i++){
			if(temp.length === 0){
				temp.push([])
			}
			temp[temp.length - 1].push(arr[i])
			if(arr[i] + 1 !== arr[i + 1] && arr[i + 1] !== undefined){
				temp.push([])
			}
		}
		return temp.map(item=>{
			if (item.length > 1){
				return `${item[0]}->${item[item.length - 1]}`
			} else {
				return `${item[0]}`
			}
		})
	}
	
	console.log(mergeArray([1,2,3,4,6,7,9,13,15]))
</script>
</html>